﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Data;
using QuantitativeInvestment.Bean;
using QuantitativeInvestment.Tools;
namespace QuantitativeInvestment.Factor
{
    class Factor
    {
        public Dictionary<string, Parameter> paraList;
        public string name;
        public DataModel dataModel;
        public string type;
        public Factor()
        {
            this.paraList = new Dictionary<string, Parameter>();
            this.dataModel = new DataModel();
            this.type = "private";
        }
        /// <summary>
        /// 给一个股票组合加入相应的因子
        /// </summary>
        /// <param name="factorTableList"></param>
        /// <param name="paraList"></param>
        public virtual void addFactorValueList(Dictionary<string,Stock> factorTableList)
        {

            
        }
        /// <summary>
        /// 给某只股票加入相应因子值
        /// </summary>
        /// <param name="stock"></param>
        /// <param name="para"></param>
        public virtual void addFactorValue(Stock stock)
        {
           
        }
        public virtual void addFactorValue( Dictionary<string, double[]> publicFactors)
        {
           
        }
        public static Factor createFactorByName(String name)
        {
            Factor factor = null;
            DataSet ds = new DataSet();
            ds.ReadXml(System.Windows.Forms.Application.StartupPath + "/Config" + "/Factors.xml");
            DataRow[] rows = ds.Tables["factor"].Select("name='"+name+"'");
            if (rows.Length > 0)
            {
                Assembly a = Assembly.GetExecutingAssembly();
                factor = (Factor)a.CreateInstance(rows[0]["objectName"].ToString());
            }

            return factor;
        }
    }
}
